#include "friend.pb.h"
#include "logger.h"
#include "mprpcapplication.h"
#include "rpcprovider.h"
#include <google/protobuf/port_def.inc>
#include <iostream>
#include <memory>
#include <string>
#include <vector>

class FriendService : public fixbug::FriendServiceRpc
{
  public:
    std::vector<std::string> GetFriendList(uint32_t userid)
    {
        std::cout << "do GetFriendList service userid : " << userid << std::endl;
        std::vector<std::string> vec;
        vec.push_back("aa");
        vec.push_back("bb");
        vec.push_back("cc");
        return vec;
    }
    void GetFriendList(::PROTOBUF_NAMESPACE_ID::RpcController *controller,
                       const ::fixbug::GetFriendListRequest *request, ::fixbug::GetFriendListResponse *response,
                       ::google::protobuf::Closure *done) override
    {
        uint32_t id = request->id();
        std::vector<std::string> friends_list = GetFriendList(id);
        response->mutable_result()->set_errcode(0);
        response->mutable_result()->set_errmsg("");
        for (std::string &name : friends_list)
        {
            response->add_friends(name);
        }
        done->Run();
    }
};

int main(int argc, char **argv)
{
    LOG_INFO("hello info");
    LOG_ERROR("hello error");
    LOG_INFO("%s %d", __FILE__, __LINE__);
    // 框架初始化
    MprpcApplication::Init(argc, argv);
    // 把 UserService 对象发布到 rpc 节点上
    RpcProvider provider;
    std::shared_ptr<FriendService> service = std::make_shared<FriendService>();
    provider.NotifyService(service.get());
    // 执行进行阻塞态，等待调用

    provider.Run();
    return 0;
}
